package cn.kdlc.demo.retrofit;

import com.squareup.okhttp.ResponseBody;

import retrofit.Call;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import rx.Observable;

/**
 * Created by hetwen on 2015/12/20 0020.
 */
public class DataManager {

    private Retrofit retrofit;

    private RetrofitService service;

    private static DataManager instance;

    public synchronized static DataManager getInstance() {
        if (instance == null) {
            instance = new DataManager();
        }
        return instance;
    }

    private DataManager() {
        retrofit = new Retrofit.Builder()
                .baseUrl(API.BASE_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        service = retrofit.create(RetrofitService.class);
    }

    public void getState(Callback<ResponseBody> callback) {
        Call<ResponseBody> call = service.getState();
        call.enqueue(callback);
    }

    public Observable<Response<ResponseBody>> getState2() {
        Observable<Response<ResponseBody>> observable = service.getState2();
        return observable;
    }

}
